package com.hq.vieorecyclerview.video.Adapter;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import static androidx.core.content.ContextCompat.startActivity;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.hq.vieorecyclerview.R;
import com.hq.vieorecyclerview.video.FullPlayActivity;

/**
 * 视频信息适配
 */
public class VideoMessageHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    private ImageView im = null;
    private TextView name = null;
    private TextView group = null;
    private TextView temp = null;
    private TextView uptemp = null;
    private VideoDate date = null;
    //图片加载器
    private RequestManager with = null;

    public VideoMessageHolder(@NonNull @NotNull View itemView) {
        super(itemView);
        this.im = itemView.findViewById(R.id.im);
        this.name = itemView.findViewById(R.id.name);
        this.group = itemView.findViewById(R.id.group);
        this.temp = itemView.findViewById(R.id.play_temp);
        this.uptemp = itemView.findViewById(R.id.uptemp);
        this.with = Glide.with(itemView);

        //注册信息
        itemView.setOnClickListener(this);
    }

    /**
     * 页面点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        //点击条目跳转到播放全屏去
        //NavController nc = Navigation.findNavController(view);
        //跳转到指定fragment
       // nc.navigate(R.id.fragment_full_play);
        Intent intent = new Intent();
        //设置成要启动的Activity
        intent.setClass(view.getContext(), FullPlayActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        view.getContext().startActivity(intent);

    }

    /**
     * 更新数据
     *
     * @param date 视频数据
     */
    public void update(VideoDate date) {
        this.date = date;
        //图片显示
        this.with.load(this.date.getImage()).into(this.im);
        //视频昵称
        this.name.setText(this.date.getName());
        //视频分组
        this.group.setText(this.date.getGroup());
        //视频时长
        this.temp.setText(this.date.getPlaytemp());
        //视频更新时间
        this.uptemp.setText(this.date.getUptemp());
    }
}
